import apiClient from '@/api/apiClient';
import { Region } from '@/pages/management/system/region/type';

import { BasicStatus, MenuType } from '#/enum';
import { OperationPkForm } from '#/form';

export enum PermissionApi {
  List = '/management/regions',
  Region = '/management/region',
}

export interface RegionItem {
  id: number;
  regionName: string;
}

export interface RegionForm {
  parentId: number;
  name: string;
  type: MenuType;
  route: string;
  status?: BasicStatus;
  operationPkForm?: OperationPkForm;
  operationArray?: string[];
  sort?: number;
  icon?: string;
  component?: string;
  hidden?: boolean;
}

const regionList = (data: any) =>
  apiClient.get<Region[]>({ url: PermissionApi.List, params: data });

const tree = () => apiClient.get<Region[]>({ url: `${PermissionApi.List}/tree` });

const createRegion = (data: RegionForm) => apiClient.post({ url: PermissionApi.Region, data });

const deleteRegion = (id: number) => apiClient.delete({ url: `${PermissionApi.Region}/${id}` });

const regionGroups = (id: number) =>
  apiClient.get<Region[]>({ url: `${PermissionApi.List}/${id}` });

const updateRegion = (id: number, data: RegionForm) =>
  apiClient.put({
    url: `${PermissionApi.Region}/${id}`,
    data,
  });

export default {
  regionList,
  createRegion,
  updateRegion,
  deleteRegion,
  regionGroups,
  tree,
};
